﻿using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Http.Controllers;
using Ross.EntityFramework.Model;
using Ross.EntityFramework;

namespace Ross.Traning.Controllers
{
    [SimpleAuthenticationFilter]
    public class NotesController:BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<bool>> Insert([FromBody] Service.Dto.Notes vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (NotesService serv = new NotesService(dbContextStr))
            {
                result = serv.Create(vm);
            }
            return Json(result);
        }

        [HttpPost]
        public JsonResult<ResultDto<bool>> Delete(int id)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (NotesService serv = new NotesService(dbContextStr))
            {
                result = serv.Delete(id);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.Notes>>> GetList(int pageindex = 1, int pagesize = 10, long userId = 0, long courseId = 0, string keywords = "")
        {
            ResultDto<List<Service.Dto.Notes>> result = new ResultDto<List<Service.Dto.Notes>>();
            using (NotesService serv = new NotesService(dbContextStr))
            {
                result = serv.GetPageList(pageindex, pagesize, userId, courseId, keywords);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<Service.Dto.Notes>> GetByID(int id)
        {
            ResultDto<Service.Dto.Notes> result = new ResultDto<Service.Dto.Notes>();
            using (NotesService serv = new NotesService(dbContextStr))
            {
                result = serv.GetByID(id);
            }
            return Json(result);
        }
        [HttpPost]
        public JsonResult<ResultDto<bool>> Update([FromBody] Service.Dto.Notes vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (NotesService serv = new NotesService(dbContextStr))
            {
                result = serv.Update(vm);
            }
            return Json(result);
        }
    }
}